package com.yunkeji.common.enums.app;

import com.yunkeji.common.exception.AppServiceException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * 客户端渠道号
 *
 * @author yunkeji
 */
@Getter
@AllArgsConstructor
public enum RoomStatus {
    房间已创建(101),
    房间已解散(102),
    进行中(103);
    private final Integer code;

    public static RoomStatus getByCode(Integer code) {
        RoomStatus[] values = RoomStatus.values();
        Optional<RoomStatus> first =
                Arrays.stream(values).filter(item -> item.getCode().equals(code)).findFirst();
        if (first.isPresent()) {
            return first.get();
        } else {
            throw AppServiceException.paramException("房间状态异常");
        }
    }
}
